package com.example.demo.result;


import com.example.demo.exception.ServiceExceptionEnum;

/**
 * 响应结果生成工具
 */
public class ResultGenerator{

    //默认成功返回msg
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";
    //默认成功返回code
    private static final Integer DEFAULT_SUCCESS_CODE = 200;
    //默认失败返回code
    private static final Integer DEFAULT_FAIL_CODE = 999999;

    /**
     * 成功,无返回值
     *
     * @return
     */
    public static RestResponse genSuccessResult() {
        return new RestResponse(DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE);
    }

    /**
     * 成功,有返回数据
     *
     * @param data
     * @return
     */
    public static RestResponse genSuccessResult(Object data) {
        return new RestResponse(DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE, data);

    }

    /**
     * 失败,返回默认code
     *
     * @param message
     * @return
     */
    public static RestResponse genFailResult(String message) {
        return new RestResponse(DEFAULT_FAIL_CODE, message);
    }

    /**
     * 失败,返回自定义code
     *
     * @param code
     * @param message
     * @return
     */
    public static RestResponse genFailResult(int code, String message) {
        return new RestResponse(code, message);
    }

    /**
     * 失败,返回自定义code
     *
     * @param exceptionEnum
     * @return
     */
    public static RestResponse genFailResult(ServiceExceptionEnum exceptionEnum) {
        return new RestResponse(exceptionEnum.getCode(), exceptionEnum.getMessage());
    }
}
